﻿Imports TwitterVB2
Public Class Form2
    Dim tw As New TwitterVB2.TwitterAPI
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        My.Settings.Username = txtUsername.Text
        My.Settings.Password = txtPassword.Text
        My.Settings.ZipCode = txtZip.Text
        My.Settings.FirstRun = "No"
        My.Settings.Save()
        GetRegion(txtZip.Text)
        GetWeather(txtZip.Text)
        GetForecast(txtZip.Text)
        My.Settings.FirstRun = "No"
        My.Settings.Save()
        Dim IsValid As Boolean = tw.ValidatePIN(Textbox1.text)
        If IsValid Then
            Dim OAuthToken As String = tw.OAuth_Token()
            Dim OAuthTokenSecret As String = tw.OAuth_TokenSecret()
            tw.AuthenticateWith("oh7NBaDDfwrhFR7WqF9w", "VnA7OYXargHBDzoPdZE4aXsvZ7o85lZXwUsUMtcI", OAuthToken, OAuthTokenSecret)
            tw.Update("WeatherTweet allowed access to your Twitter Profile.")
            My.Settings.OAuthToken = OAuthToken
            My.Settings.OAuthTokenSecret = OAuthTokenSecret
            My.Settings.Save()
        End If
    End Sub

    Private Sub btnAuthorize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAuthorize.Click
        MsgBox("Please Allow the application, enter the PIN then hit the Save button. After this is done once you will no longer need to do it.")
        Dim Url As String = tw.GetAuthorizationLink("oh7NBaDDfwrhFR7WqF9w", "VnA7OYXargHBDzoPdZE4aXsvZ7o85lZXwUsUMtcI")
        Process.Start(Url)
    End Sub

    Private Sub picClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picClose.Click
        Me.Close()
    End Sub
End Class